package control;

import service.HomeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/home/*")
public class HomeServlet extends BaseServlet {
    private HomeService homeService=new HomeService();

    /**
     * 查询当日新增的文章，会议和用户
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findHomeCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        // 1. 查询今日注册用户/今日新增文章/今日发布会议等数据
        Map<String,Object> homeCount=homeService.findHomeCount();

        // 2. 查询近七日的数据汇总信息
        List<List<Long>> homeDetail=homeService.findHomeDetail();

        // 3. 将两个数据封装成一个Map响应到前端
        Map<String,Object> returnMap = new HashMap();
        returnMap.put("homeCount",homeCount);
        returnMap.put("homeDetail",homeDetail);

        // 转换为JSON写出到前端
        writerObjToString(response,returnMap);

    }

}
